Skip to content

fix ResponseMetaDataTransformer #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Jun 19, 2025

While working with API Gateway and trying to snapshot responses coming from AWS_PROXY Integration Subtypes, AWS will return a response containing the ResponseMetadata field but already filtered, with no HTTPHeaders field in it.

The current ResponseMetaDataTransformer will always try access the HTTPHeaders field as a dict, even if the value from http_headers = metadata.get("HTTPHeaders") is None, raising this exception:

                for h in headers_to_collect:
>                   if http_headers.get(h):
E                   AttributeError: 'NoneType' object has no attribute 'get'
../localstack_snapshot/snapshots/transformer.py:110: AttributeError

As a workaround, I've implemented a hack like that:
service_resp["_ResponseMetadata"] = service_resp.pop("ResponseMetadata")

This PR now properly fixes it, and adds some test for the transformer.

I'd like to note that it seems we were trying to get the Content-Type header from the response, but as the value was wrong, it was never captured in any snapshots.
Adding it now would need a full refresh, or a big skip, so this is out of scope of this PR.

For the release version, I'd say this could be a 0.3.1?

@bentsku bentsku self-assigned this Jun 19, 2025
@bentsku bentsku added the bug Something isn't working label Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant